/**
 * Created by Lzzzzzq on 2017/3/14.
 */
import React from 'react'
import {render} from 'react-dom'
import Model from './model'

const div = document.createElement('div')
document.body.appendChild(div)
const container = render(<Model />, div)

const info = (msg = '', duration = 1000) => {
  show({ type: 'msg', msg: msg, duration: duration })
}

const success = (msg = '', duration = 1000) => {
  show({ type: 'success', msg: msg, duration: duration })
}

const fail = (msg = '', duration = 1000) => {
  show({ type: 'fail', msg: msg, duration: duration })
}

const offline = (msg = '网络错误', duration = 1000) => {
  show({ type: 'offline', msg: msg, duration: duration })
}

/**
 * loading
 * @method loading
 * @param  {Number} [typeStatus=1] 1加载，2加载完成
 */
const loading = (typeStatus = 1, msg = '正在加载') => {
  show({ type: 'loading', msg: msg, typeStatus: typeStatus })
}

const show = opt => {
  opt = opt || {}
  if (opt.msg) {
    container.show(opt)
  }
}

module.exports = {
  info,
  success,
  fail,
  offline,
  loading,
  show
}
